@ECHO OFF
@REM  ----------------------------------------------------------------------------
@REM  InstallCertificates.cmd file
@REM
@REM  This cmd file will set up the Relevant certificates to run a self- hosted 
@REM  Application which requires certificate-based security.
@REM  
@REM  ----------------------------------------------------------------------------

echo.
echo ================================================================
echo  InstallCertificates.bat file
echo    This batch file allows you to configure the server with
echo    relevant certificates to run a self-hosted application 
echo    that requires server certificate-based security.
echo ================================================================
echo.

PAUSE 

echo off
setlocal
echo ************
echo Certificate Setup Starting
echo ************

REM cleans up certs from previous runs.
echo ****************
echo CleanUp Starting
echo ****************

echo -------------------------
echo Deleting Client Certificates
echo -------------------------
echo off
certmgr.exe -del -r CurrentUser -s My -c -n indigoarchitects.com > NUL
echo off
certmgr.exe -del -r CurrentUser -s TrustedPeople -c -n indigoarchitects.com > NUL


echo -------------------------
echo Deleting Server Certificates
echo -------------------------
certmgr.exe -del -r LocalMachine -s My -c -n indigoarchitects.com > NUL
echo off
certmgr.exe -del -r LocalMachine -s Root -c -n indigoarchitects.com > NUL

echo *****************
echo Cleanup completed
echo *****************

echo ************
echo Server Certificate Setup starting
echo ************
echo Creating Server Certificate
echo ************

makecert -r -pe -n CN=indigoarchitects.com -ss my -sr currentuser -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 indigoarchitects.com.cer

certmgr -add -r CurrentUser -s My -c -n indigoarchitects.com -r CurrentUser -s TrustedPeople


echo ************
echo Copying Server Certificates to Client's CurrentUser store
echo ************
certmgr -add -r CurrentUser -s My -c -n indigoarchitects.com -r LocalMachine -s Root
certmgr -add -r CurrentUser -s My -c -n indigoarchitects.com -r LocalMachine -s My

